package com.ultimate.management.util.response;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * Jwt响应请求
 * @Author LH
 * @Date 2024/1/16 19:41
 * @PackageName com.ultimate.management.util.response
 * @Description: [项目名小写 多个单词用_分隔 | 包名全部小写 | 类 首字母大写 | 变量和方法 首字母小写，多个单词组成时除首字母，其他字母首字母需大写 | 常量 全部大写,多个单词用'_'分割]
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Component
public class JwtResponse{
    private Boolean success;//是否成功

    private Integer code;//状态码

    private String message;//状态码的解释信息

    private Map<String, Object> data=new HashMap<>();


    //成功静态方法
    public static JwtResponse ok() {
        JwtResponse r = new JwtResponse();
        r.setSuccess(true); ;
        r.setCode(BaseCode.SUCCESS);r.setMessage("成功");
        return r;
    }
    //失败静态方法
    public static JwtResponse error() {
        JwtResponse r = new JwtResponse();
        r.setSuccess(false);
        r.setCode (BaseCode.FAIL);r.setMessage("失败");
        return r;
    }

    public JwtResponse success(Boolean success){
        this.setSuccess(success);
        return this;
    }


    public JwtResponse message (String message){
        this.setMessage(message);
        return this;
    }
    public JwtResponse code (Integer code){
        this.setCode(code);
        return this;
    }
    public JwtResponse data( String key, Object value){
        this.data.put(key, value);
        return this;
    }

    public JwtResponse data(Map<String,Object> map){
        this.setData(map);
        return this;
    }
}
